#!/usr/bin/env node

const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const ejs = require('ejs')
inquirer.prompt([
  {
    type: 'input',
    name: "name",
    message: 'Project name?'
  }
]).then(res => {
  //生成文件
  const tmpDir = path.join(__dirname, 'templates');
  const desDir = process.cwd();
  fs.readdir(tmpDir, (err, files) => {
    if (err) throw err
    files.forEach(file => {
      ejs.renderFile(path.join(tmpDir, files), res, (err, result) => {
        if (err) throw err
        fs.writeFileSync(path.join(desDir, file), result);
      })
    })
  })
})